home *** CD-ROM | disk | FTP | other *** search
- /******************** ***********************/
- //
- // Player PRO 5.0 - DRIVER SOURCE CODE -
- //
- // Library Version 5.0
- //
- // To use with MAD Library for Mac: Symantec, CodeWarrior and MPW
- //
- // Antoine ROSSET
- // 16 Tranchees
- // 1206 GENEVA
- // SWITZERLAND
- //
- // COPYRIGHT ANTOINE ROSSET 1996, 1997, 1998
- //
- // Thank you for your interest in PlayerPRO !
- //
- // FAX: (+41 22) 346 11 97
- // PHONE: (+41 79) 203 74 62
- // Internet: RossetAntoine@bluewin.ch
- //
- /******************** ***********************/
-
- #include "MOD.h"
- #include "MAD.h"
- #include "MADH.h"
- #include "RDriver.h"
-
- #if defined(powerc) || defined(__powerc)
- enum {
- PlayerPROPlug = kCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof( OSType)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof( Ptr)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof( MADMusic*)))
- | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof( PPInfoRec*)))
- | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof( MADDriverSettings*)))
- };
-
- ProcInfoType __procinfo = PlayerPROPlug;
- #else
- #include <A4Stuff.h>
- #endif
-
- Ptr MADPlugNewPtr( long size, MADDriverSettings* init)
- {
- if( init->sysMemory) return NewPtrSys( size);
- else return NewPtr( size);
- }
-
- Ptr MADPlugNewPtrClear( long size, MADDriverSettings* init)
- {
- if( init->sysMemory) return NewPtrSysClear( size);
- else return NewPtrClear( size);
- }
-
- enum
- {
- ins = 1,
- note = 2,
- cmd = 4,
- argu = 8,
- vol = 16
- };
-
- oldPatData* oldDecompressPartitionMAD1( oldMADSpec *header, oldPatData* myPat)
- {
- oldPatData* finalPtr;
- Byte *srcPtr;
- oldCmd *myCmd;
- short maxCmd;
- Byte set;
-
- finalPtr = ( oldPatData*) NewPtrClear( sizeof( oldPatHeader) + myPat->header.size * header->numChn * sizeof( oldCmd));
- if( finalPtr == 0L) return 0L;
-
- BlockMoveData( myPat, finalPtr, sizeof( oldPatHeader));
-
- srcPtr = (Byte*) myPat->Cmds;
- myCmd = (oldCmd*) finalPtr->Cmds;
- maxCmd = finalPtr->header.size * header->numChn;
-
- /*** Decompression Routine ***/
-
- while( maxCmd != 0)
- {
- maxCmd--;
-
- myCmd->cmd = 0;
- myCmd->note = 0xFF;
- myCmd->arg = 0;
- myCmd->ins = 0;
- myCmd->vol = 0xFF;
-
- set = *srcPtr++;
-
- if( set & ins) myCmd->ins = *srcPtr++;
- if( set & note) myCmd->note = *srcPtr++;
- if( set & cmd) myCmd->cmd = *srcPtr++;
- if( set & argu) myCmd->arg = *srcPtr++;
- if( set & vol) myCmd->vol = *srcPtr++;
-
- myCmd++;
- }
-
- return finalPtr;
- }
-
- oldCmd* GetOldCommand( short PosX, short TrackIdX, oldPatData* tempMusicPat)
- {
- if( PosX < 0) PosX = 0;
- else if( PosX >= tempMusicPat->header.size) PosX = tempMusicPat->header.size -1;
-
- return( &(tempMusicPat->Cmds[ (tempMusicPat->header.size * TrackIdX) + PosX]));
- }
-
- Cmd* GetMADCommand( register short PosX, register short TrackIdX, register PatData* tempMusicPat)
- {
- if( PosX < 0) PosX = 0;
- else if( PosX >= tempMusicPat->header.size) PosX = tempMusicPat->header.size -1;
-
- return( & (tempMusicPat->Cmds[ (tempMusicPat->header.size * TrackIdX) + PosX]));
- }
-
- void pStrcpy(register unsigned char *s1, register unsigned char *s2)
- {
- register short len, i;
-
- len = *s2;
- for ( i = 0; i <= len; i++) s1[ i] = s2[ i];
- }
-
- void mystrcpy( Ptr a, Ptr b)
- {
- BlockMove( b + 1, a, b[ 0]);
- }
-
- OSErr MADH2Mad( Ptr MADPtr, long size, MADMusic *theMAD, MADDriverSettings *init)
- {
- short i, x;
- long inOutCount, OffSetToSample = 0L, z;
- OSErr theErr = noErr;
- Ptr tempPtr;
- long finetune[16] =
- {
- 8363, 8413, 8463, 8529, 8581, 8651, 8723, 8757,
- 7895, 7941, 7985, 8046, 8107, 8169, 8232, 8280
- };
-
-
- /**** Old MADH variables ****/
-
- oldMADSpec *oldMAD;
-
- oldMAD = (oldMADSpec*) MADPtr;
-
-
- /**** HEADER ****/
- if( oldMAD->MAD != 'MADH') return MADFileNotSupportedByThisPlug;
- OffSetToSample += sizeof( oldMADSpec);
-
- // Conversion
- inOutCount = sizeof( MADSpec);
- theMAD->header = (MADSpec*) MADPlugNewPtrClear( inOutCount, init);
- if( theMAD->header == 0L) return MADNeedMemory;
-
- theMAD->header->MAD = 'MADI';
-
- BlockMove( oldMAD->name, theMAD->header->name, 32);
- theMAD->header->numPat = oldMAD->numPat;
- theMAD->header->numChn = oldMAD->numChn;
- theMAD->header->numPointers = oldMAD->numPointers;
- BlockMove( oldMAD->oPointers, theMAD->header->oPointers, 256);
- theMAD->header->speed = oldMAD->speed;
- theMAD->header->tempo = oldMAD->tempo;
-
- mystrcpy( theMAD->header->infos, (Ptr) "\pConverted by PlayerPRO MAD-F-G Plug (⌐Antoine ROSSET <rossetantoine@bluewin.ch>)");
-
- /**** Patterns *******/
-
- for( i = 0; i < oldMAD->numPat; i++)
- {
- struct oldPatData *tempPat, *tempPat2;
- struct oldPatHeader tempPatHeader;
-
- /** Lecture du header de la partition **/
- inOutCount = sizeof( struct oldPatHeader);
- BlockMoveData( MADPtr + OffSetToSample, &tempPatHeader, inOutCount);
-
- /*************************************************/
- /** Lecture du header + contenu de la partition **/
- /*************************************************/
-
- if( tempPatHeader.compMode == 'MAD1')
- {
- inOutCount = sizeof( oldPatData) + tempPatHeader.patBytes;
- }
- else
- {
- inOutCount = sizeof( oldPatData) + oldMAD->numChn * tempPatHeader.size * sizeof( oldCmd);
- }
-
- tempPat = (struct oldPatData*) MADPlugNewPtr( inOutCount, init);
- if( tempPat == 0L) DebugStr("\pMemory Prob1");
-
- BlockMove( MADPtr + OffSetToSample, tempPat, inOutCount);
- OffSetToSample += inOutCount;
-
- if( tempPat->header.compMode == 'MAD1')
- {
- tempPat2 = oldDecompressPartitionMAD1( oldMAD, tempPat);
-
- DisposePtr( (Ptr) tempPat);
-
- tempPat = tempPat2;
- }
-
- /**************/
- /* CONVERSION */
- /**************/
-
- theMAD->partition[ i] = (PatData*) MADPlugNewPtrClear( sizeof( PatHeader) + theMAD->header->numChn * tempPat->header.size * sizeof( Cmd), init);
- if( theMAD->partition[ i] == 0L) return MADNeedMemory;
-
- theMAD->partition[ i]->header.size = tempPat->header.size;
- theMAD->partition[ i]->header.compMode = 'NONE';
-
- BlockMove( tempPat->header.name, theMAD->partition[ i]->header.name, 20);
-
- theMAD->partition[ i]->header.patBytes = 0L; theMAD->partition[ i]->header.unused2 = 0L;
-
- for( x = 0; x < theMAD->partition[ i]->header.size; x++)
- {
- for( z = 0; z < theMAD->header->numChn; z++)
- {
- struct oldCmd *oldCmd;
- Cmd *aCmd;
-
- aCmd = GetMADCommand( x, z, theMAD->partition[ i]);
-
- oldCmd = GetOldCommand( x,
- z,
- tempPat);
-
- aCmd->ins = oldCmd->ins;
- aCmd->note = oldCmd->note;
- aCmd->cmd = oldCmd->cmd;
- aCmd->arg = oldCmd->arg;
- aCmd->vol = oldCmd->vol;
- aCmd->unused = oldCmd->unused;
- }
- }
-
- DisposePtr( (Ptr) tempPat);
- tempPat = 0L;
- }
- for( i = theMAD->header->numPat; i < MAXPATTERN ; i++) theMAD->partition[ i] = 0L;
-
- for( i = 0; i < MAXTRACK; i++)
- {
- if( i % 2 == 0) theMAD->header->chanPan[ i] = MAX_PANNING/4;
- else theMAD->header->chanPan[ i] = MAX_PANNING - MAX_PANNING/4;
-
- theMAD->header->chanVol[ i] = MAX_VOLUME;
- }
-
- theMAD->header->generalVol = 64;
- theMAD->header->generalSpeed = 80;
- theMAD->header->generalPitch = 80;
-
- /**** Instruments header *****/
-
- theMAD->fid = ( InstrData*) MADPlugNewPtrClear( sizeof( InstrData) * (long) MAXINSTRU, init);
- if( !theMAD->fid) return MADNeedMemory;
-
- theMAD->sample = ( sData**) MADPlugNewPtrClear( sizeof( sData*) * (long) MAXINSTRU * (long) MAXSAMPLE, init);
- if( !theMAD->sample) return MADNeedMemory;
-
- for( i = 0; i < MAXINSTRU; i++) theMAD->fid[ i].firstSample = i * MAXSAMPLE;
-
- for( i = 0; i < 64; i++)
- {
- InstrData *curIns = &theMAD->fid[ i];
-
- BlockMove( oldMAD->fid[ i].name, theMAD->fid[ i].name, 32);
-
- theMAD->fid[ i].type = oldMAD->fid[ i].type;
- theMAD->fid[ i].numSamples = oldMAD->fid[ i].numSamples;
- BlockMove( oldMAD->fid[ i].what, theMAD->fid[ i].what, 96);
- BlockMove( oldMAD->fid[ i].volEnv, theMAD->fid[ i].volEnv, 12 * sizeof( EnvRec));
- BlockMove( oldMAD->fid[ i].pannEnv, theMAD->fid[ i].pannEnv, 12 * sizeof( EnvRec));
- theMAD->fid[ i].volSize = oldMAD->fid[ i].volSize;
- theMAD->fid[ i].pannSize = oldMAD->fid[ i].pannSize;
- theMAD->fid[ i].volSus = oldMAD->fid[ i].volSus;
- theMAD->fid[ i].volBeg = oldMAD->fid[ i].volBeg;
- theMAD->fid[ i].volEnd = oldMAD->fid[ i].volEnd;
- theMAD->fid[ i].pannSus = oldMAD->fid[ i].pannSus;
- theMAD->fid[ i].pannBeg = oldMAD->fid[ i].pannBeg;
- theMAD->fid[ i].pannEnd = oldMAD->fid[ i].pannEnd;
- theMAD->fid[ i].volType = oldMAD->fid[ i].volType;
- theMAD->fid[ i].pannType = oldMAD->fid[ i].pannType;
- theMAD->fid[ i].volFade = oldMAD->fid[ i].volFade;
- theMAD->fid[ i].vibDepth = oldMAD->fid[ i].vibDepth;
- theMAD->fid[ i].vibRate = oldMAD->fid[ i].vibRate;
-
- for( x = 0; x < oldMAD->fid[ i].numSamples ; x++)
- {
- oldsData *oldcurData;
- sData *curData;
-
- oldcurData = (oldsData*) (MADPtr + OffSetToSample);
- OffSetToSample += sizeof( oldsData);
-
- curData = theMAD->sample[ i*MAXSAMPLE + x] = (sData*) MADPlugNewPtrClear( sizeof( sData), init);
-
- curData->size = oldcurData->size;
- curData->loopBeg = oldcurData->loopBeg;
- curData->loopSize = oldcurData->loopSize;
- curData->vol = oldcurData->vol;
- curData->c2spd = oldcurData->c2spd;
- curData->loopType = oldcurData->loopType;
- curData->amp = oldcurData->amp;
- // curData->panning = oldcurData->panning;
- curData->relNote = oldcurData->relNote;
-
- curData->data = MADPlugNewPtr( curData->size, init);
- if( curData->data == 0L) return MADNeedMemory;
-
- BlockMove( MADPtr + OffSetToSample, curData->data, curData->size);
- OffSetToSample += curData->size;
- }
- }
-
- return noErr;
- }
-
- OSErr TestoldMADFile( Ptr AlienFile)
- {
- OSType *myMADSign = (OSType*) AlienFile;
-
- if( *myMADSign == 'MADH') return noErr;
- else return MADFileNotSupportedByThisPlug;
- }
-
- OSErr ExtractoldMADInfo( PPInfoRec *info, Ptr AlienFile)
- {
- oldMADSpec *myMOD = ( oldMADSpec*) AlienFile;
- long PatternSize;
- short i;
- short tracksNo;
-
- /*** Signature ***/
-
- info->signature = myMOD->MAD;
-
- /*** Internal name ***/
-
- myMOD->name[ 31] = '\0';
- MADstrcpy( info->internalFileName, myMOD->name);
-
- /*** Tracks ***/
-
- info->totalTracks = myMOD->numChn;
-
- /*** Total Patterns ***/
-
- info->totalPatterns = 0;
- for( i = 0; i < 128; i++)
- {
- if( myMOD->oPointers[ i] >= info->totalPatterns) info->totalPatterns = myMOD->oPointers[ i];
- }
- info->totalPatterns++;
-
- /*** Partition Length ***/
-
- info->partitionLength = myMOD->numPointers;
-
- /*** Total Instruments ***/
-
- for( i = 0, info->totalInstruments = 0; i < 64 ; i++)
- {
- if( myMOD->fid[ i].numSamples > 0) info->totalInstruments++;
- }
-
- MADstrcpy( info->formatDescription, "MADH Plug");
-
- return noErr;
- }
-
- /*****************/
- /* MAIN FUNCTION */
- /*****************/
-
- OSErr main( OSType order, char *AlienFileName, MADMusic *MadFile, PPInfoRec *info, MADDriverSettings *init)
- {
- OSErr myErr;
- Ptr AlienFile;
- short vRefNum, iFileRefI;
- long dirID, sndSize;
-
- #ifndef powerc
- long oldA4 = SetCurrentA4(); //this call is necessary for strings in 68k code resources
- #endif
-
- c2pstr( AlienFileName);
-
- myErr = noErr;
-
- switch( order)
- {
- case 'IMPL':
- myErr = FSOpen( (unsigned char*) AlienFileName, 0, &iFileRefI);
- if( myErr == noErr)
- {
- GetEOF( iFileRefI, &sndSize);
-
- // ** MEMORY Test Start
- AlienFile = MADPlugNewPtr( sndSize * 2L, init);
- if( AlienFile == 0L) myErr = MADNeedMemory;
- // ** MEMORY Test End
-
- else
- {
- DisposePtr( AlienFile);
-
- AlienFile = MADPlugNewPtr( sndSize, init);
- myErr = FSRead( iFileRefI, &sndSize, AlienFile);
- if( myErr == noErr)
- {
- myErr = TestoldMADFile( AlienFile);
- if( myErr == noErr)
- {
- myErr = MADH2Mad( AlienFile, GetPtrSize( AlienFile), MadFile, init);
- }
- }
- DisposePtr( AlienFile); AlienFile = 0L;
- }
- FSClose( iFileRefI);
- }
- break;
-
- case 'TEST':
- myErr = FSOpen( (unsigned char*) AlienFileName, 0, &iFileRefI);
- if( myErr == noErr)
- {
- sndSize = 5000L; // Read only 5000 first bytes for optimisation
-
- AlienFile = MADPlugNewPtr( sndSize, init);
- if( AlienFile == 0L) myErr = MADNeedMemory;
- else
- {
- myErr = FSRead( iFileRefI, &sndSize, AlienFile);
- myErr = TestoldMADFile( AlienFile);
-
- DisposePtr( AlienFile); AlienFile = 0L;
- }
- FSClose( iFileRefI);
- }
- break;
-
- case 'INFO':
- myErr = FSOpen( (unsigned char*) AlienFileName, 0, &iFileRefI);
- if( myErr == noErr)
- {
- GetEOF( iFileRefI, &info->fileSize);
-
- sndSize = 5000L; // Read only 5000 first bytes for optimisation
-
- AlienFile = MADPlugNewPtr( sndSize, init);
- if( AlienFile == 0L) myErr = MADNeedMemory;
- else
- {
- myErr = FSRead( iFileRefI, &sndSize, AlienFile);
- if( myErr == noErr)
- {
- myErr = ExtractoldMADInfo( info, AlienFile);
- }
- DisposePtr( AlienFile); AlienFile = 0L;
- }
- FSClose( iFileRefI);
- }
- break;
-
- default:
- myErr = MADOrderNotImplemented;
- break;
- }
-
- p2cstr( (unsigned char*) AlienFileName);
-
- #ifndef powerc
- SetA4( oldA4);
- #endif
- return myErr;
- }